package com.company;

import java.util.concurrent.atomic.AtomicInteger;

public class Main {

    public static void main(String[] args) {
        thread(1);
        thread(1);
        thread(0);
    }

    private static AtomicInteger aInt= new AtomicInteger(0);

    private static void thread(int num){
        Thread thread = new Thread(){
            public void run(){
                while (aInt.get()<100){
                    int next = aInt.get();
                    if(next%2==num){
                        System.out.println("thread"+num+":"+next);
                        aInt.incrementAndGet();
                    }
                }
            }
        };
        thread.start();
    }
}
